import { login } from '@/api/user'
import { setToken, getToken, removeToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    // 修改token
    SET_TOKEN(state, token) {
      state.token = token
      setToken(token)
    },
    REMOVE_TOKEN(state) {
      state.token = ''
      removeToken()
    }
  },
  actions: {
    async fetchLogin(store, loginForm) {
      const { data } = await login(loginForm)
      store.commit('SET_TOKEN', data.token)
      return data
    }
  }
}
